package com.ljf.spring;

import com.ljf.framework.context.LjfContext;
import com.ljf.framework.context.model.LjfRequest;
import com.ljf.framework.context.model.LjfResponse;
import com.ljf.framework.context.model.LjfStorage;
import com.ljf.servlet.model.LjfRequestForServlet;
import com.ljf.servlet.model.LjfResponseForServlet;
import com.ljf.servlet.model.LjfStorageForServlet;
import org.springframework.util.AntPathMatcher;


/**
 * 上下文处理器 [ SpringMVC版本实现 ]
 */
public class LjfContextForSpring implements LjfContext {

	/**
	 * 获取当前请求的Request对象
	 */
	@Override
	public LjfRequest getRequest() {
		return new LjfRequestForServlet(SpringMVCUtil.getRequest());
	}

	/**
	 * 获取当前请求的Response对象
	 */
	@Override
	public LjfResponse getResponse() {
		return new LjfResponseForServlet(SpringMVCUtil.getResponse());
	}

	/**
	 * 获取当前请求的 [存储器] 对象
	 */
	@Override
	public LjfStorage getStorage() {
		return new LjfStorageForServlet(SpringMVCUtil.getRequest());
	}

	/**
	 * 校验指定路由匹配符是否可以匹配成功指定路径
	 */
	@Override
	public boolean matchPath(String pattern, String path) {
		return new AntPathMatcher().match(pattern, path);
	}

	/**
	 * 此上下文是否有效
	 */
	@Override
	public boolean isValid() {
		return SpringMVCUtil.isWeb();
	}

	@Override
	public void syncContext(Object object) {
		SpringMVCUtil.syncContext(object);
	}

	@Override
	public Object getSyncObject() {
		return SpringMVCUtil.getSyncObject();
	}

}
